home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / program / libkb100.zip / LIBKB-1.00 / UTIL / MKDIST.PL < prev    next >
Perl Script  |  1996-07-23  |  2KB  |  119 lines

  1. #!/usr/bin/perl
  2. ##
  3. ## vi:ts=4
  4. ##
  5. ##---------------------------------------------------------------------------##
  6. ##  Author:
  7. ##      Markus F.X.J. Oberhumer         markus.oberhumer@jk.uni-linz.ac.at
  8. ##  Copyright:
  9. ##      Copyright (C) 1995, 1996 Markus F.X.J. Oberhumer
  10. ##      For conditions of distribution and use, see copyright notice in kb.h 
  11. ##  Description:
  12. ##      Select files for tar/zip distribution
  13. ##---------------------------------------------------------------------------##
  14.  
  15. @Files = (
  16.     'bin/*dos.exe',
  17.     'bin/*lnx.out',
  18.     'bin/*nt.exe',
  19.     'bin/*os2.exe',
  20.     'bin/cwsdpmi*',
  21. ###    'jump/*',
  22.     'desc.sdi',
  23.     'cha*log',
  24.     'copying*',
  25.     'file_id.diz',
  26.     'makefile*',
  27.     'readme*',
  28.     '*.bat',
  29.     '*.btm',
  30.     '*.c',
  31.     '*.doc',
  32.     '*.h',
  33.     '*.hh',
  34.     '*.in',
  35.     '*.lsm',
  36.     '*.mk',
  37.     '*.mod',
  38.     '*.pl',
  39. );
  40.  
  41. # config
  42. $dirsep  = $ENV{'COMSPEC'} ? '\\' : '/';        # directory separator
  43.  
  44. # get dirname
  45. $dirname = shift;            
  46. $dirname .= $dirsep if $dirname;    # add trailing '/'
  47.  
  48. # make a Perl regexp
  49. $Files = '(^|[\\\/])((' . join(')|(', @Files) . '))$';
  50. $Files =~ s/\./\\\./g;                # quote all '.'
  51. $Files =~ s/\*/\.\*/g;                # change all '*' to '.*'
  52.  
  53.  
  54. #
  55. # process files or stdin
  56. #
  57.  
  58. @f = ();
  59.  
  60. $i = 0;
  61. while (<>) {
  62.     chop;
  63.     next if /^\s*$/;                # skip empty lines
  64.     next if /^\s*\#/;                # skip comment lines
  65.  
  66.     next if /^\.{1,2}$/;            # skip '.' and '..'
  67.  
  68.     s/\\/\//g;
  69.  
  70.     ## s/^(\.\.\/)+//;                # remove leading '../'
  71.     s/^(\.\/)+//;                    # remove leading './'
  72.  
  73.     next unless (/$Files/io);        # ignore case in filename matching
  74.  
  75.     push(@f,${dirname} . $_); 
  76.     $i++;
  77. }
  78.  
  79. # print info message
  80. print STDERR "$0: $i files\n";
  81.  
  82.  
  83. #
  84. # sort
  85. #
  86.  
  87. sub ext_cmp {
  88.     local ($aa, $bb);
  89.  
  90.     #        |dir| |file  | |  ext?  | | ext  |
  91.     $a =~ m%^(.*/)?([^./]+)?([^./]*\.)*([^./]*)$%;
  92.     $aa = $4 . '.' . $2 . '.' . $1;
  93.     $aa =~ tr/A-Z/a-z/;
  94.     $b =~ m%^(.*/)?([^./]+)?([^./]*\.)*([^./]*)$%;
  95.     $bb = $4 . '.' . $2 . '.' . $1;
  96.     $bb =~ tr/A-Z/a-z/;
  97.     ## print STDERR "$a='$aa'   $b='$bb'\n";
  98.  
  99.     $aa cmp $bb;
  100. }
  101.  
  102. # sort by extension
  103. ## @f = sort(ext_cmp @f);
  104.  
  105. # sort by name
  106. ## @f = sort(@f);
  107.  
  108.  
  109. #
  110. # print
  111. #
  112.  
  113. for (@f) {
  114.     s/\//$dirsep/g;
  115.     print "$_\n";
  116. }
  117.  
  118. exit(0);
  119.